using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.DataTier.Source;

namespace OR.Lazarus.Library.DataTier.Source.Lazarus
{
	/// <summary>
	/// Defines an implementation of an existing object's definition.  This is expressed in OOP through inheritance, and in relational databases according to the DBMethod property.
	/// </summary>
   public class ImplementDetail : EntityBase
   {
		protected System.String mName;
		protected string mRef;
		protected string mDBMethod;
		protected string mDescription;

		public ImplementDetail()
		{
	
		}
	
		/// <summary>
		/// Specifies a unique name for the entity.
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// Specifies an object who's definition will be extended.
		/// </summary>
		public string Ref
		{
			get
			{
				return ( mRef );
			}
			set
			{
				mRef = value;
			}
		}

		/// <summary>
		/// Defines the inheritance behavior in Relational Databases.  A method of Aggregate will add the object's fields into the ancestor table, while a method of Category will create a Relational Category (type of) relationship between the ancestor and descendant.
		/// </summary>
		public string DBMethod
		{
			get
			{
				return ( mDBMethod );
			}
			set
			{
				mDBMethod = value;
			}
		}

		/// <summary>
		/// Provides a long-text description for the entity.
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mRef = DataUtility.GetString( pSource, "ref" );
			mDBMethod = DataUtility.GetString( pSource, "db-method" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lz:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lz", "implement", "http://schemas.icitadel.com/Lazarus/Source.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mRef ) )
			{
				vNewElement.SetAttribute( "ref", mRef );
			}
					
			if ( !String.IsNullOrEmpty( mDBMethod ) )
			{
				vNewElement.SetAttribute( "db-method", mDBMethod );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lz", "description", "http://schemas.icitadel.com/Lazarus/Source.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.ImplementDetail v_oReturn = new Derived.ImplementDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Ref = mRef;
			v_oReturn.DBMethod = mDBMethod;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.ImplementDetail CloneTyped()
		{
			return ( ( Derived.ImplementDetail )this.Clone() );
		}
   }
}
   